package com.qk.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.dto.ActivitiesDto;
import com.qk.entity.Activity;
import com.qk.service.ActivityService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/activities")
public class ActivityController {
    @Autowired
    private ActivityService activityService;
//1、条件分页查询活动列表
    @GetMapping
    public Result listActivities(ActivitiesDto activitiesDto)
    {
        log.info("查询活动列表，参数：{}", activitiesDto);
        PageResult<Activity> pageResult = activityService.listActivities(activitiesDto);
        return Result.success(pageResult);
    }
    //添加活动
    @PostMapping
    public Result addActivity(@RequestBody Activity activity)
    {
        log.info("添加活动，参数：{}", activity);
        activityService.addActivity(activity);
        return Result.success();
    }
    //根据ID查询活动
    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id)
        {
            log.info("查询活动：{}", id);
            Activity activity = activityService.getById(id);
            return Result.success(activity);
        }
    //修改活动
    @PutMapping
    public Result update(@RequestBody Activity activity)
        {
            log.info("修改活动，参数：{}", activity);
            activityService.update(activity);
            return Result.success();
        }
    //查询指定类型的活动
    @GetMapping("/type/{type}")
    public Result getByType(@PathVariable Integer type)
        {
            log.info("查询指定类型的活动：{}", type);
            List<Activity> activityList = activityService.getActivitesByType(type);
            return Result.success(activityList);
        }
    //删除活动
    @DeleteMapping("/{ids}")
    public Result delete(@PathVariable List<Integer> ids)
        {
            log.info("删除活动：{}", ids);
            activityService.delActivity(ids);
            return Result.success();
        }
    //查询所有活动
    @GetMapping("/list")
    public Result getlist()
        {
            log.info("查询所有活动");
            List<Activity> list = activityService.list();
            return Result.success(list);
        }









}
